//
//  SettingsAndHelp.m
//  iPhoneControlApplication
//
//  Created by Elliot Chapple on 11/04/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "Settings.h"


@implementation Settings

@synthesize ipAddress;
@synthesize portNumber;
@synthesize saveAndConfirmButton;


//Methods

-(IBAction)textFieldDoneEditing:(id)sender
{
	[sender resignFirstResponder];
}







-(IBAction)saveAndConfirmButtonSelected
{	
	
	UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Save Settings?" delegate:self cancelButtonTitle:@"Cancel Save" destructiveButtonTitle:@"Confirm Save!" otherButtonTitles:nil];
	[actionSheet showInView:self.view];
	[actionSheet release];
	
}

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
	if (!(buttonIndex == [actionSheet cancelButtonIndex]))
	{
		NSString *msg = nil;
		
		if (ipAddress.text.length > 0)
			msg = [[NSString alloc] initWithFormat:@"Settings Have Been Saved with:\nIP Address: %@\nPort Number %@.",ipAddress.text, portNumber.text];
		else
			msg = [[NSString alloc] initWithFormat:@"Unable to Save Settings due to invalid IP Address: %@",ipAddress.text];
		
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Save Settings" message:msg delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
		[alert show];
		[alert release];
		[msg release];
	}
}





//Apple Standard Code
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	UIImage *buttonImageNormal = [UIImage imageNamed:@"MC Zero Button (70x70).png"];
	UIImage *stretchableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ saveAndConfirmButton setBackgroundImage:stretchableButtonImageNormal forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed = [UIImage imageNamed:@"MC 0 Button Selected (70x70).png"];
	UIImage *stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[saveAndConfirmButton setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
    [super dealloc];
}


@end
